require(['jquery', 'cookie', 'app', 'lay'], function ($) {
    require(['vue'], function (Vue) {
        layui.use(['form', 'laydate', 'upload'], function () {
            var form = layui.form;
            form.render();
            form.on('submit(formDemo)', function (data) {
                dic.that['image'] = JSON.stringify(dic.that.image);
                dic.that['note'] = JSON.stringify(dic.that.note);
                var re = playPost("v1/api/shop/save", "", JSON.stringify(dic.that));
                alr(re.msg);
                setTimeout(function () {
                    window.reload();
                }, 500);
                return false;
            });
            var upload = layui.upload;
            //执行实例
            var uploadInst = upload.render({
                elem: '#upload' //绑定元素
                , url: configPro.server_img_interface //上传接口
                , done: function (res) {
                    if (dic.that.image == null) {
                        dic.that.image = new Array();
                        dic.that.image.push(res.data.data.src);
                    } else {
                        dic.that.image.push(res.data.data.src);
                    }
                }
                , error: function (res) {
                    alr("上传失败");
                }
                , accept: 'file'
            });
            var uploadInstX = upload.render({
                elem: '#uploadX' //绑定元素
                , url: configPro.server_img_interface //上传接口
                , done: function (res) {
                    if (dic.that.note == null) {
                        dic.that.note = new Array();
                        dic.that.note.push(res.data.data.src);
                    } else {
                        dic.that.note.push(res.data.data.src);
                    }
                }
                , error: function (res) {
                    alr("上传失败");
                }
                , accept: 'file'
            });
        });
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                where: [],
                that: {
                    id: "",
                    name: "",
                    spack: "",
                    image: [],
                    money: "",
                    note: []
                }
            }
            , created: function () {
                var uuid = new acquire().parameterMap['id'];
                if (uuid != null) {
                    var da = playGet("v1/api/shop/" + uuid).data;
                    this.that = da;
                    this.that.image = JSON.parse(this.that.image);
                    this.that.note = JSON.parse(this.that.note);
                }
            }
            , methods: {
                delNote: function (i) {
                    var re = this.that.image;
                    re.splice(i, 1);
                    this.that.image = re;
                },
                delNoteX: function (i) {
                    var re = this.that.note;
                    re.splice(i, 1);
                    this.that.note = re;
                },
                referXadmin: function () {
                    window.location.reload();
                },
                delG: function (i) {
                    var sp = this.spec;
                    this.spec = sp - 1;
                    var list = this.specList;
                    list.splice(i, 1);
                    this.specList = list;
                },
            }
        });
    })
});
